  #include<stdio.h>
#include<sqlite3.h> 
#include<string.h>
#include <stdlib.h>
int main(int argc,char **argv)
{
    int id;
    int age;

    char name[20];

    char sql[1024]={0};
    char*errmsg;

    if(argc!=2)
    {
        printf("please input db name\n");
        return 1;
    }
    sqlite3 * db;
    int ret=sqlite3_open(argv[1],&db);

    if(ret!=SQLITE_OK)
    {
        printf("sqlite3_open error%s",sqlite3_errmsg(db));
        return 1;
    }
    printf("sqlite open db successful!\n");
    strcpy(sql,"create table IF NOT EXISTS student(id integer primary key,name text,age integer);");
    ret= sqlite3_exec(db,sql,nullptr,nullptr,&errmsg);
    if(ret!=SQLITE_OK)
    {
        printf("exec error:%s\n",sqlite3_errmsg(db));
    }
    char ** result;
    int nrow;
    int ncol;
    memset(sql,0,strlen(sql));
    strcpy(sql,"select * from student");
    ret= sqlite3_get_table(db,sql,&result,&nrow,&ncol,&errmsg);
    if(ret!=SQLITE_OK)
    {
        printf("select error:%s\n",sqlite3_errmsg(db));
    }
    for(int i=0;i<=nrow;i++)
    {
        for(int j=0;j<=ncol;j++)
        {
            printf("%s|",result[i*ncol+j]);   
        }
        printf("\n");
    }
    sqlite3_close(db);
    return 0;
}